package com.feeyo.groundservice.composewidget.usage

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color.Companion.DarkGray
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.unit.dp
import com.feeyo.groundservice.composewidget.usage.base.BaseComposeActivity
import com.feeyo.groundservice.composewidget.view.drag_list.grid.DragDropLazyVerticalGrid
import com.feeyo.groundservice.composewidget.view.drag_list.list.DragDropLazyColumn

/**
 *作者：70893 on 2025-06-10
 *描述：拖拽的列表
 */

data class DraggableItem(
    val text: String
)

class DragListActivity : BaseComposeActivity() {

    val list = mutableStateListOf(
        DraggableItem(text = "Item 1"),
        DraggableItem(text = "Item 2"),
        DraggableItem(text = "Item 3"),
        DraggableItem(text = "Item 4"),
        DraggableItem(text = "Item 5"),
        DraggableItem(text = "Item 6"),
        DraggableItem(text = "Item 7"),
        DraggableItem(text = "Item 8"),
        DraggableItem(text = "Item 9"),
        DraggableItem(text = "Item 10"),
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Column {
                DragDropLazyColumn(
                    items = list,
                    draggable = true,
                    onDragStart = {},
                    onDrag = { from, to ->
                        list.add(to, list.removeAt(from))
                    },
                    onDragEnd = {
                        // do nothing
                    },
                    itemContent = { modifier, item, isDragging ->
                        DraggableListItem(
                            modifier = modifier.height(40.dp),
                            item = item
                        )
                    },
                    verticalArrangement = Arrangement.spacedBy(5.dp),
                    contentPadding = PaddingValues(16.dp)
                )

                DragDropLazyVerticalGrid(
                    items = list,
                    draggable = true,
                    columCount = 3,
                    onDragStart = {},
                    onDrag = { from, to ->
                        list.add(to, list.removeAt(from))
                    },
                    onDragEnd = {
                        // do nothing
                    },
                    itemContent = { modifier, item, isDragging ->
                        DraggableListItem(
                            modifier = modifier.height(50.dp),
                            item = item
                        )
                    },
                    horizontalArrangement = Arrangement.spacedBy(10.dp),
                    verticalArrangement = Arrangement.spacedBy(10.dp),
                )
            }

        }
    }


    @Composable
    fun DraggableListItem(
        modifier: Modifier,
        item: DraggableItem,
    ) {
        Card(modifier = modifier, colors = CardDefaults.cardColors(containerColor = DarkGray)) {
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Text(text = item.text, modifier = Modifier, color = White)
            }
        }
    }
}